from django.db import models

# Create your models here.
#用户表
class User(models.Model):
    username = models.CharField(max_length=50,primary_key=True)
    password = models.CharField(max_length=50)
    shenfen = models.IntegerField(choices=[(0, '学生'), (1, '管理员')])
#设备分类表
class Sbfl(models.Model):
    flname = models.CharField(max_length=50)
    # 父分类ID允许为空（顶级分类）
    Sid = models.ForeignKey('self', on_delete=models.CASCADE, related_name='aa', null=True, blank=True)
    datetime = models.DateTimeField(auto_now_add=True)
#设备信息表
class Sbxx(models.Model):
    sbname = models.CharField(max_length=50)
    numbers = models.CharField(max_length=50, unique=True)
    sbflid = models.ForeignKey(Sbfl, on_delete=models.CASCADE, related_name='ac')
    price = models.DecimalField(max_digits=10, decimal_places=2)
    # 修正IntegerField定义（添加括号）
    integer = models.IntegerField()
    status = models.IntegerField(choices=[(0, '正常'), (1, '维修'), (2, '报废')])
#设备借用表
class Jy(models.Model):
    sbid = models.ForeignKey(Sbxx, on_delete=models.CASCADE, related_name='ab')
    # 修正IntegerField定义（添加括号）
    jinteger = models.IntegerField()
    jyr = models.CharField(max_length=50)
    jdatetime = models.DateTimeField(auto_now_add=True)
    ydatetime = models.DateTimeField()  # 预计归还日期不应设为auto_now_add
    # 实际归还日期允许为空（未归还时）
    sdatetime = models.DateTimeField(null=True, blank=True)